package HOANGTHANHCONG_SWING_BAI2;

import java.awt.EventQueue;

import javax.swing.JFrame;
import java.awt.Toolkit;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JComboBox;
import javax.swing.DefaultComboBoxModel;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class bai2 {		controlle ctl1 = new controlle();
model model1 = new model();

	private JFrame frmBaiTapIfelse;
	private JTextField txtsoa;
	private JTextField txtsob;
	private JTextField txtkq;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		controlle ctl1 = new controlle();
		model model1 = new model();
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					bai2 window = new bai2();
					window.frmBaiTapIfelse.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the application.
	 */
	public bai2() {
		initialize();
	}

	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		frmBaiTapIfelse = new JFrame();
		frmBaiTapIfelse.setTitle("Bai Tap if..else");
		frmBaiTapIfelse.setIconImage(Toolkit.getDefaultToolkit().getImage(bai2.class.getResource("/HOANGTHANHCONG_SWING_Bai1/insurance.png")));
		frmBaiTapIfelse.setBounds(100, 100, 450, 300);
		frmBaiTapIfelse.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frmBaiTapIfelse.getContentPane().setLayout(null);
		
		JLabel lblNewLabel = new JLabel("Nhập vào số a: ");
		lblNewLabel.setBounds(22, 32, 176, 36);
		frmBaiTapIfelse.getContentPane().add(lblNewLabel);
		
		JLabel lblNewLabel_1 = new JLabel("Nhập vào số b:");
		lblNewLabel_1.setBounds(22, 85, 125, 23);
		frmBaiTapIfelse.getContentPane().add(lblNewLabel_1);
		
		JLabel lblChnPhpTon = new JLabel("Chọn phép toán: ");
		lblChnPhpTon.setBounds(22, 140, 125, 14);
		frmBaiTapIfelse.getContentPane().add(lblChnPhpTon);
		
		JLabel lblKtQu = new JLabel("Kết quả: ");
		lblKtQu.setBounds(22, 185, 46, 14);
		frmBaiTapIfelse.getContentPane().add(lblKtQu);
		
		txtsoa = new JTextField();
		txtsoa.setBounds(112, 40, 257, 20);
		frmBaiTapIfelse.getContentPane().add(txtsoa);
		txtsoa.setColumns(10);
		
		txtsob = new JTextField();
		txtsob.setBounds(112, 86, 257, 20);
		frmBaiTapIfelse.getContentPane().add(txtsob);
		txtsob.setColumns(10);
		
		final JComboBox cbbpheptoan = new JComboBox();
		cbbpheptoan.setModel(new DefaultComboBoxModel(new String[] {"", "Cộng ", "Trừ", "Nhân ", "Chia"}));
		cbbpheptoan.setBounds(112, 137, 155, 20);
		frmBaiTapIfelse.getContentPane().add(cbbpheptoan);
		
		txtkq = new JTextField();
		txtkq.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				model1.setA(Integer.parseInt(txtsoa.getText()));
				model1.setB(Integer.parseInt(txtsob.getText()));
				if (cbbpheptoan.getSelectedIndex()==0){
					txtkq.setText("Bạn chưa chọn phép toán");
				}
				if (cbbpheptoan.getSelectedIndex()==1){
					
					int k =ctl1.cong(model1.getA(), model1.getB());
					
					txtkq.setText(""+k);
				}
				if (cbbpheptoan.getSelectedIndex()==2){
				int k =	ctl1.tru(model1.getA(), model1.getB());
				txtkq.setText(""+k);
					
				}
				if (cbbpheptoan.getSelectedIndex()==3){
					int k =	ctl1.nhan(model1.getA(), model1.getB());
					txtkq.setText(""+k);
					}
				if (cbbpheptoan.getSelectedIndex()==4){
					txtkq.setText(ctl1.chia(model1.getA(), model1.getB()));
						
					}
			}
		});
		txtkq.setBounds(112, 185, 257, 66);
		frmBaiTapIfelse.getContentPane().add(txtkq);
		txtkq.setColumns(10);
	}
}
